Homework 5

Cellular automata

Cellular automata were invented in the 1950s by John von Neumann as formal models of self-reproducing machines. The field was revived in the 1980s by Stephen Wolfram. Wolfram is also the author of the program Mathematica. His early papers are available on his web site. He has spent the last nine years writing a new book on cellular automata. Titled A New Kind of Science, he believes it will revolutionize many fields. An interesting profile God, Stephen Wolfram, and Everything Else by Michael S. Malone was recently in Forbes ASAP.

5.1 One-dimensional cellular automata

Our cellular automata consist of a single-dimensional array of cells. Based on their long-term behavior, Stephen Wolfram divided cellular automata rules into four distinct classes. Wolfram is currently fascinated by class III rule 30

He sees this pattern in many areas of nature, such as pigmentation on seashells. He believes cellular automata are the key to understanding how simple rules produce complex structures and behavior.

Many other variations on cellular automata have been studied:

5.2 Update rules in Python

Here's a Python function to calculate the new value of a cell, given the sum of the cell and 2 nearest neighbors on each side, and the rule code:
def updateForSum(sum,rule):
    mask = 1 << sum
    if (rule & mask) != 0:
        return 1
        return 0
You don't have to understand how this function works to use it, but here's an explanation.

The rules codes can be represented as binary numbers instead of decimal.

The function uses Python's bit-level operators << and &. So the function reads the column of the transition table corresponding to the sum passed in.

Yes, if you don't know binary arithmetic this explanation probably doesn't help. Try this site and this one if you want to know more.

5.3 Cellular automata in Python

Your assignment is to write a program to display one-dimensional cellular automata. First create a list with as many cells (elements) as your chosen screen width. To display the list in the window, iterate over each cell and use the livewires plot function:
To calculate a new generation, first copy the list to a temporary list. The temporary list now becomes the current list. During debugging you should use a small display (say 50x50). Generating 400x400 displays takes a LONG time in Python...

Don't forget to call livewires.clear_screen() when you start to display a new code rule.

Also, the drawable area of the livewires display window appears to be a few pixels shorter than the requested height. Try leaving a few blank lines at the top to ensure you are displaying all the data (the first line should always look random).

When your program is working, try out different code rules. You may even find one that impresses Stephen.